package com.lanou3g.code0416;

import java.io.*;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/4/16;
 * Otherwise, I don't know who created it either
 */

public class Test04 {
    public static void main(String[] args) {
//        save();
        load();



    }

    private static void load(){
        FileInputStream fis = null;
        ObjectInputStream ois = null;

        try {
            fis = new FileInputStream("person");
            ois = new ObjectInputStream(fis);

            Person o = (Person) ois.readObject();

            System.out.println(o.getName());
            System.out.println(o.getAge());

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeAll(ois);
        }
    }

    private static void save() {
        FileOutputStream fos = null;

        ObjectOutputStream oos = null;
        Person person = new Person();
        person.setName("张三");
        person.setAge(12);

        try {
            fos = new FileOutputStream("person");
            oos = new ObjectOutputStream(fos);

            oos.writeObject(person);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeAll(oos);
        }
    }
}
